package org.freespace.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.freespace.model.User;
import org.freespace.utils.SessionUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
@Component
public class SessionInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User user = (User) SessionUtil.getSession().getAttribute(SessionUtil.USER_REDIS_KEY);
        if (user == null) {
            // throw no login
        }
        return true;
    }
}
